<template>
	<view :style="$theme.pageStyle">
		<view style="margin: 20rpx;position: relative;top: 0;">
			<u-swiper height="130" :list="isbanner" keyName="img" circular @change="swiperIndex = $event.current"
				radius="10"></u-swiper>
			<view style="
			font-size: 24rpx;
			background: #ff0800a0;
			border-radius: 20rpx 0rpx 20rpx 0;
			padding: 6rpx 20rpx;
			position: absolute;
			bottom: 0;
			right: 0;
			" v-if="isbanner.length">
				<text style="color: #fff;">{{swiperIndex+1}}/{{isbanner.length}}</text>
			</view>
		</view>

		<view class="menu-nav">
			<scroll-view scroll-x @scroll="ScrollMenu" class="nav-list">
				<view class="nav" ref="nav" :style="navList.length<=10?'flex-direction:row':''">
					<view class="list" v-for="(item,index) in navList" @click="ToUrl(item.url)" :key="item.id">
						<image :src="item.images" mode=""></image>
						<text>{{item.name}}</text>
					</view>
				</view>
			</scroll-view>
			<view class="indicator" v-if="navList.length>10">
				<view class="plan">
					<view class="bar" :style="'left:'+slideNum+'%'"></view>
				</view>
			</view>
		</view>

		<view
			style="display: flex;flex-direction: column;padding: 20rpx;background: #fff;margin: 10px;border-radius: 8px;">
			<text style="font-weight: 600;">推荐关注</text>
			<scroll-view scroll-x style="margin-top: 30rpx;">
				<u-row>
					<block v-for="(item,index) in users" :key="index">
						<view
							style="display: flex;flex-direction: column;align-items: center;border-radius: 20rpx;background-color: #ff08000a;padding: 20rpx;margin-right: 20rpx;flex-shrink: 0;">
							<view style="position: relative;" @click="ToUrl('/pages/lawyer/info?id=' + item.id )">
								<u-avatar :src="item.avatar"></u-avatar>
							</view>
							<view class="u-line-1" style="margin-top: 10px;">
								<text style="margin-top: 20rpx;">{{item.real_name?item.real_name:'-'}}</text>
							</view>
							<view class="btns" @click="follow(item.id)">关注</view>
							<!-- <view class="btns" @click="follow(item.id)">取消关注</view> -->
						</view>
					</block>
				</u-row>
			</scroll-view>
		</view>


		<block v-for="(item,index) in ArticleList" :key="index">
			<view class="articles-item" @click="ToUrl('/article/index/detail?id=' + item.id )">
				<view class="essay-item">
					<view class="title van-ellipsis">
						{{item.title}}
					</view>
					<view class="essay-item-container flex">
						<view class="contents flex-1">
							<view class="">
								<view class="detail text-ellipsis-2">
									{{item.abstract}}
								</view>
							</view>
							<view class="info flex flex-space-between flex-align-center">
								<view class="flex flex-1">
									<view class="tag">
										# {{item.category.name}}
									</view>
									<view class="number-of-read flex flex-align-center">
										<p class="text">{{item.click_actual}}浏览</p>
									</view>
								</view>
								<p class="date">{{$u.timeFrom(item.create_time,'mm月dd日')}}</p>
							</view>
						</view>
						<view>
							<image class="logo" :src="item.images" mode=""></image>
						</view>
					</view>
				</view>
			</view>
		</block>


		<view style="height: 50px;">

		</view>


	</view>
</template>

<script>
	import $H from '@/common/js/request.js';
	export default {
		components: {},
		data() {
			return {
				swiperIndex: '',
				isbanner: [],
				navList: [],
				users: [],
				ArticleList: [],
				isLoading: false,
				ShowLoading: true,
				isfollow: false,
				scroll: false,
				status: 0,
				pages: 1,
				limit: 15,
				page: 0,
				out: 0,
				DataList: [],
				scrollTop: 0,
			}
		},
		onLoad() {
			this.timeer()
		},
		onShow() {
			this.IndexData()
		},
		onPageScroll(e) {
			this.scrollTop = e.scrollTop;
		},
		onReachBottom() {
			this.GetData();
		},
		methods: {
			ScrollMenu() {},
			IndexData() {
				this.$api.ArticleApi.index().then(res => {
					if (res.code == 1) {
						this.navList = res.data.navs
						this.isbanner = res.data.banner
						this.users = res.data.users
					}
				})
			},
			Tourl(url) {
				uni.navigateTo({
					url: url
				})
			},
			timeer() {
				this.ArticleList = [];
				this.isLoading = false;
				this.scroll = false;
				this.status = 0;
				this.pages = 1;
				this.page = 0;
				this.out = 0;
				this.GetData();
			},
			follow(id) {
				$H.post('user/follow', {
					'id': id,
					'follow': 1
				}, {
					token: true
				}).then(res => {
					uni.$u.toast(res.msg)
					this.isfollow = !this.isfollow
				})
			},
			GetData(e) {
				if (this.isLoading) {
					return;
				}
				if (this.page < this.pages) {
					this.out = 0;
					this.isLoading = true;
					this.scroll = false;
					this.status = 1;
					this.limit = 15;
					var page = this.page + 1;
					$H.post('article/alists', {
						'page': page,
						'limit': this.limit,
					}, {
						token: true
					}).then(res => {
						if (res.code == 1) {
							var list = res.data.data;
							for (let i = 0; i < list.length; i++) {
								//将数据逐条写入数组
								this.ArticleList.push(list[i]);
							}
							this.pages = res.data.last_page;
							this.page = page;
							this.scroll = true;
							this.isLoading = false;
							setTimeout(() => {
								this.ShowLoading = false
							}, 1000);

							this.out = 1;
							if (this.page == this.pages || res.data.total == 0) {
								this.status = 2;
							} else {
								this.status = 0;
							}
						} else {
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 2000
							});
						}
					})
				}
			},
			ToUrl(url) {
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.btns {
		height: 20px;
		margin-top: 10px;
		background: #fab6b6;
		color: #fa3534;
		border-radius: 4px;
		line-height: 20px;
		font-size: 12px;
		padding: 0 10px 0px 15px;
		text-align: center;
	}

	.menu-nav {
		position: relative;
		height: 300rpx;
		margin: 30rpx auto;
		margin: 10px;
		background: #fff;
		border-radius: 8px;
		padding: 10px;

		.nav-list {
			white-space: nowrap;
			height: 270rpx;
			width: 100%;

			.nav {
				display: inline-block;
				display: flex;
				flex-direction: column;
				flex-wrap: wrap;
				justify-content: space-between;
				height: 270rpx;
			}

			.list {
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				width: 20%;
				height: 130rpx;
				margin-bottom: 20rpx;

				image {
					width: 75rpx;
					height: 75rpx;
					border-radius: 100%;
				}

				text {
					font-size: 26rpx;
					color: #363636;
					margin-top: 10rpx;
				}
			}
		}

		.indicator {
			position: absolute;
			left: 0;
			bottom: 0;
			display: flex;
			justify-content: center;
			align-items: center;
			width: 100%;
			height: 30rpx;

			.plan {
				position: relative;
				width: 100rpx;
				height: 8rpx;
				border-radius: 8rpx;
				background-color: #e1e1e1;

				.bar {
					position: absolute;
					width: 50%;
					height: 100%;
					border-radius: 6rpx;
					background-color: var(--color-primary);
				}
			}
		}
	}

	::v-deep .u-grid-item--hover-class {
		opacity: 1 !important;
	}

	.article {
		background: #fff;
		padding: 30rpx 30rpx 12rpx 30rpx;
		padding-bottom: 10rpx;
	}



	.articles-item {
		margin: 10px;
		overflow: hidden;
		padding-bottom: 10px;
		border-radius: 8px;
		// border-bottom: 1px #f1f1f1 solid;
	}

	.essay-item {
		background: #fff;
		padding: 10px;
	}

	.essay-item .title {
		font-size: 18px;
		font-weight: 500;
		color: #333;
	}

	.van-ellipsis {
		overflow: hidden;
		white-space: nowrap;
		text-overflow: ellipsis;
	}

	.essay-item-container {
		padding: 5px 0;
	}

	.essay-item .essay-item-container .contents {
		overflow: hidden;
	}

	.flex-1 {
		flex: 1;
	}

	.essay-item .essay-item-container .contents .detail {
		margin-bottom: 10px;
		font-size: 14px;
		font-weight: 400;
		color: #666;
		height: 40px;
	}

	.text-ellipsis-2 {
		display: -webkit-box;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		overflow: hidden;
		word-wrap: break-word;
		word-break: break-all;
	}

	.flex-align-center {
		align-items: center;
	}

	.flex-space-between {
		justify-content: space-between;
	}

	.essay-item .essay-item-container .contents .info .tag {
		font-size: 14px;
		font-weight: 400;
		color: var(--color-primary);
	}

	.essay-item .essay-item-container .contents .info .number-of-read {
		padding-left: 10px;
	}

	.essay-item .essay-item-container .contents .info .number-of-read .text {
		font-size: 14px;
		font-weight: 400;
		color: #999;
	}

	.essay-item .essay-item-container .contents .info .date {
		font-size: 14px;
		line-height: 16px;
		font-weight: 400;
		color: #999;
	}

	.essay-item .essay-item-container .logo {
		width: 100px;
		height: 60px;
		border-radius: 8px;
		overflow: hidden;
		display: block;
		margin-left: 14px;
	}
</style>